<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>多媒体资源管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
           /* var floor = $("#imageGroup\\.toFloor").val();
            if(floor == "false"){
				/!*  alert("aaaaaa")*!/
                $('.floorval').val("");
                $(".floor").css("cssText", "display:none;");
				/!*$(".floor").css("display","none");*!/
//                $("#videoSource").attr("style","display:visible");
            }else{

				/!* alert("aaaavvvvvvvvvvvaa")*!/
                $(".floor").css("cssText", "display:visible;");
				/!*  $("#videoSource").attr("style","display:none");*!/
            }
*/
            floorChange();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('<spring:message code="common.subbmiting"/>');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				},
                rules:{
                    "imageGroup.interval":{
                        isIntGtZero:true
                    }
                },
                //如果验证控件没有message，将调用默认的信息
                messages:{
                    "imageGroup.interval":{
                        isIntGtZero:"请输入大于0的整数"
                        //isFloat:"请输入浮点数"
                        //isInteger:"请输入整数"
                    }

                }
			});
		});

		function addRow(list, idx, tpl, row){
            var floor = $("#imageGroup\\.toFloor").val();
            if(floor == "false"){
                tpl = tpl.replace("<td class=\"floor\">", "<td class=\"floor\" style=\"display: none\">");
            }else{
            }

			var addRow = "yes";
			var editRow = "";
			if(row != null){
				addRow = "";
				editRow = "yes";
			}
			var rowIdx = idx+1;
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row,addRow:addRow,editRow:editRow,rowIdx:rowIdx
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "<spring:message code='common.delete'/>");
				$(obj).parent().parent().removeClass("error");
			}
		}
		function sourceTypeChange(){
			var type = $("#type").val();
			if(type == "video"){
				$("#imageSource").attr("style","display:none");
				$("#videoSource").attr("style","display:visible");
			}else{
				$("#imageSource").attr("style","display:visible");
				$("#videoSource").attr("style","display:none");
			}
		}

        function floorChange(){
		   /* var id="imageGroup.toFloor";*/
            var floor = $("#imageGroup\\.toFloor").val();
            if(floor == "false"){
              /*  alert("aaaaaa")*/
                $('.floorval').val("");
                $(".floor").css("cssText", "display:none;");
                /*$(".floor").css("display","none");*/
//                $("#videoSource").attr("style","display:visible");
            }else{

               /* alert("aaaavvvvvvvvvvvaa")*/
               $(".floor").css("cssText", "display:visible;");
				/*  $("#videoSource").attr("style","display:none");*/
            }
        }
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/source/eleSourceMultimedia/">多媒体资源列表</a></li>
		<li class="active"><a href="${ctx}/source/eleSourceMultimedia/form?id=${eleSourceMultimedia.id}">多媒体资源<shiro:hasPermission name="source:eleSourceMultimedia:edit">${not empty eleSourceMultimedia.id?'<spring:message code="common.modify"/>':'<spring:message code="common.add"/>'}</shiro:hasPermission><shiro:lacksPermission name="source:eleSourceMultimedia:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="eleSourceMultimedia" action="${ctx}/source/eleSourceMultimedia/save" method="post" class="form-horizontal">
	<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label"><spring:message code="common.dname"/>：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="25" class="input-large required" />
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">类型：</label>
			<div class="controls">
				<form:select path="type" class="input-small " onchange="sourceTypeChange();">
					<form:options items="${fns:getDictList('multimedia')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<c:choose>
			<c:when test="${eleSourceMultimedia.type == 'image' }">		<div id="imageSource" style="display:visible;">
			</c:when>
			<c:otherwise>		<div id="imageSource" style="display:none;">
			</c:otherwise>
		</c:choose>
		<div class="control-group">
			<label class="control-label">自动播放：</label>
			<div class="controls">
				<form:select path="imageGroup.autoPlay" class="input-small ">
					<form:options items="${fns:getDictList('falsetrue')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">过渡效果：</label>
			<div class="controls">
				<form:select path="imageGroup.transitionEffect" class="input-small ">
					<form:options items="${fns:getDictList('transition_effect')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">播放的间隔时间(秒)：</label>
			<div class="controls">
				<form:input path="imageGroup.interval" htmlEscape="false" maxlength="7" class="input-small  required"/>秒
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">对应楼层：</label>
			<div class="controls">
				<form:select path="imageGroup.toFloor" class="input-small " onchange="floorChange();">
					<form:options items="${fns:getDictList('truefalse')}" itemLabel="label" itemValue="value" htmlEscape="false"  />
				</form:select>
			</div>
		</div>
		
			<div class="control-group" >
				<label class="control-label">图片资源：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th>图片名称</th>
								<th>播放序列序号<font color="red">*</font></th>
								<th>图片<font color="red">*</font></th>
								<th class="floor">对应的楼层</th>
								<%--<th><spring:message code='common.remarks'/></th>--%>
								<shiro:hasPermission name="source:image:eleSourceImageGroup:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="eleSourceImageList">
						</tbody>
						<shiro:hasPermission name="source:image:eleSourceImageGroup:edit"><tfoot>
							<tr><td colspan="7"><a href="javascript:" onclick="addRow('#eleSourceImageList', eleSourceImageRowIdx, eleSourceImageTpl);eleSourceImageRowIdx = eleSourceImageRowIdx + 1;" class="btn">新增</a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="eleSourceImageTpl">//<!--
						<tr id="imageGroup.eleSourceImageList{{idx}}">
							<td class="hide">
								<input id="imageGroup.eleSourceImageList{{idx}}_id" name="imageGroup.eleSourceImageList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="imageGroup.eleSourceImageList{{idx}}_delFlag" name="imageGroup.eleSourceImageList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							{{#editRow}}	
							<td>
								<input id="imageGroup.eleSourceImageList{{idx}}_name" name="imageGroup.eleSourceImageList[{{idx}}].name" type="text" value="{{row.name}}" maxlength="255" class="input-small "/>
							</td>
							{{/editRow}}
							{{#addRow}}	
							<td>
								<input id="imageGroup.eleSourceImageList{{idx}}_name" name="imageGroup.eleSourceImageList[{{idx}}].name" type="text" value="{{rowIdx}}" maxlength="255" class="input-small "/>
							</td>
							{{/addRow}}	
							<td>
								<input id="imageGroup.eleSourceImageList{{idx}}_index" name="imageGroup.eleSourceImageList[{{idx}}].index" type="text" value="{{row.index}}" maxlength="10" class="input-small  digits required"/>
							</td>
							<td>
								<input type="hidden" path="imageGroup.eleSourceImageList[{{idx}}].path" name="imageGroup.eleSourceImageList[{{idx}}].path" id="path_{{idx}}" htmlEscape="false" class="input-xlarge required" value="{{row.path}}"/>
								<sys:ckfinder input="path_{{idx}}" type="images" uploadPath="/source/image" selectMultiple="false"/>
							</td>
							<td class="floor">
								<input id="imageGroup.eleSourceImageList{{idx}}_correspondingFloor" name="imageGroup.eleSourceImageList[{{idx}}].correspondingFloor" type="text" value="{{row.correspondingFloor}}" maxlength="255" class="input-small floorval" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"/>
							</td>
						<%--	<td>
								<textarea id="eleSourceImageList{{idx}}_remarks" name="eleSourceImageList[{{idx}}].remarks" rows="1" maxlength="255" class="input-small ">{{row.remarks}}</textarea>
							</td>--%>
							<shiro:hasPermission name="source:image:eleSourceImageGroup:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#eleSourceImageList{{idx}}')" title="<spring:message code='common.delete'/>">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var eleSourceImageRowIdx = 0, eleSourceImageTpl = $("#eleSourceImageTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(eleSourceMultimedia.imageGroup.eleSourceImageList)};
							for (var i=0; i<data.length; i++){
								addRow('#eleSourceImageList', eleSourceImageRowIdx, eleSourceImageTpl, data[i]);
								eleSourceImageRowIdx = eleSourceImageRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>
			</div>
			<c:choose>
			<c:when test="${eleSourceMultimedia.type == 'image' }">		<div class="control-group" id="videoSource" style="display:none">
			</c:when>
			<c:otherwise>		<div class="control-group" id="videoSource">
			</c:otherwise>
		</c:choose>
			
				<label class="control-label">视频：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th><spring:message code="common.dname"/></th>
								<th>开始播放日期</th>
								<th>结束播放日期</th>
								<th>开始播放时间</th>
								<th>结束播放时间</th>
								<th>连续播放次数<font color="red">*</font> </th>
								<th>播放序列序号<font color="red">*</font> </th>
								<th>视频</th>
								<th>直播链接</th>
								<shiro:hasPermission name="source:video:eleSourceVideoGroup:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="eleSourceVideoList">
						</tbody>
						<shiro:hasPermission name="source:video:eleSourceVideoGroup:edit"><tfoot>
							<tr><td colspan="9"><a href="javascript:" onclick="addRow('#eleSourceVideoList', eleSourceVideoRowIdx, eleSourceVideoTpl);eleSourceVideoRowIdx = eleSourceVideoRowIdx + 1;" class="btn">新增</a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="eleSourceVideoTpl">//<!--
						<tr id="videoGroup.eleSourceVideoList{{idx}}">
							<td class="hide">
								<input id="videoGroup.eleSourceVideoList{{idx}}_id" name="videoGroup.eleSourceVideoList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="videoGroup.eleSourceVideoList{{idx}}_delFlag" name="eleSourceVideoList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							{{#editRow}}	
							<td>
								<input id="videoGroup.eleSourceVideoList{{idx}}_name" name="videoGroup.eleSourceVideoList[{{idx}}].name" type="text" value="{{row.name}}" maxlength="255" class="input-small "/>
							</td>
							{{/editRow}}	
							{{#addRow}}	
							<td>
								<input id="videoGroup.eleSourceVideoList{{idx}}_name" name="videoGroup.eleSourceVideoList[{{idx}}].name" type="text" value="{{rowIdx}}" maxlength="255" class="input-small "/>
							</td>
							{{/addRow}}
							<td>
								<input id="videoGroup.eleSourceVideoList{{idx}}_startDate" name="videoGroup.eleSourceVideoList[{{idx}}].startDate" type="text" readonly="readonly" maxlength="20" class="input-small Wdate "
									value="{{row.startDate}}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
							</td>
							<td>
								<input id="videoGroup.eleSourceVideoList{{idx}}_endDate" name="videoGroup.eleSourceVideoList[{{idx}}].endDate" type="text" readonly="readonly" maxlength="20" class="input-small Wdate "
									value="{{row.endDate}}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
							</td>
							<td>
								<input id="videoGroup.eleSourceVideoList{{idx}}_startTime" name="videoGroup.eleSourceVideoList[{{idx}}].startTime" type="text" readonly="readonly" maxlength="20" class="input-small Wdate "
									value="{{row.startTime}}" onclick="WdatePicker({dateFmt:'HH:mm:ss',isShowClear:false});"/>
							</td>
							<td>
								<input id="videoGroup.eleSourceVideoList{{idx}}_endTime" name="videoGroup.eleSourceVideoList[{{idx}}].endTime" type="text" readonly="readonly" maxlength="20" class="input-small Wdate "
									value="{{row.endTime}}" onclick="WdatePicker({dateFmt:'HH:mm:ss',isShowClear:false});"/>
							</td>
							{{#editRow}}
							<td>
								<input id="videoGroup.eleSourceVideoList{{idx}}_frequency" name="videoGroup.eleSourceVideoList[{{idx}}].frequency" type="text" value="{{row.frequency}}" maxlength="10" class="input-mini  digits required"/>
							</td>
							{{/editRow}}	
							{{#addRow}}	
							<td>
								<input id="videoGroup.eleSourceVideoList{{idx}}_frequency" name="videoGroup.eleSourceVideoList[{{idx}}].frequency" type="text" value="1" maxlength="10" class="input-mini  digits required"/>
							</td>
							{{/addRow}}
							{{#editRow}}
							<td>
								<input id="videoGroup.eleSourceVideoList{{idx}}_index" name="videoGroup.eleSourceVideoList[{{idx}}].index" type="text" value="{{row.index}}" maxlength="10" class="input-mini digits required"/>
							</td>
							{{/editRow}}	
							{{#addRow}}	
							<td>
								<input id="videoGroup.eleSourceVideoList{{idx}}_index" name="videoGroup.eleSourceVideoList[{{idx}}].index" type="text" value="{{rowIdx}}" maxlength="10" class="input-mini digits required"/>
							</td>
							{{/addRow}}
							<td>
								<input path="videoGroup.eleSourceVideoList{{idx}}_path" name="videoGroup.eleSourceVideoList[{{idx}}].path" id="video_path_{{idx}}" type="hidden" value="{{row.path}}" maxlength="255"/>
								<sys:ckfinder input="video_path_{{idx}}" type="videos" uploadPath="/source/video/eleSourceVideoGroup" selectMultiple="false"/>
							</td>
							<td>
								<textarea id="videoGroup.eleSourceVideoList{{idx}}_liveUrl" name="videoGroup.eleSourceVideoList[{{idx}}].liveUrl" rows="2" maxlength="255" class="input-small ">{{row.liveUrl}}</textarea>
							</td>
							<shiro:hasPermission name="source:video:eleSourceVideoGroup:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#eleSourceVideoList{{idx}}')" title="<spring:message code='common.delete'/>">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var eleSourceVideoRowIdx = 0, eleSourceVideoTpl = $("#eleSourceVideoTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(eleSourceMultimedia.videoGroup.eleSourceVideoList)};
							for (var i=0; i<data.length; i++){
								addRow('#eleSourceVideoList', eleSourceVideoRowIdx, eleSourceVideoTpl, data[i]);
								eleSourceVideoRowIdx = eleSourceVideoRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>
			<div class="control-group">
			<label class="control-label"><spring:message code='common.remarks'/>：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="2" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="source:image:eleSourceImageGroup:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>